//-----------------------------------------------------------------------------
// File: ChartHandlerBase.cs
//
// Copyright (c) Dmitry Shuklin. All rights reserved.
//-----------------------------------------------------------------------------
using System;

namespace ObjectiveDraw.Platform
{
	/// <summary>
	/// Summary description for ChartHandlerBase.
	/// </summary>
	public class ChartMouseHandlerBase : Cerebrum.Integrator.GenericComponent
	{
		public event System.Windows.Forms.MouseEventHandler MouseDown;
		public event System.Windows.Forms.MouseEventHandler MouseMove;
		public event System.Windows.Forms.MouseEventHandler MouseUp;

		public ChartMouseHandlerBase()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		protected System.Drawing.Point m_DownMousePosition;
		protected bool m_MouseIsDown = false;

		public ObjectiveDraw.Platform.Application DrawerApplication
		{
			get
			{
				return this.DomainContext.Properties[ObjectiveDraw.Platform.Application.m_ApplicationProperty] as ObjectiveDraw.Platform.Application;
			}
		}

		public virtual System.Windows.Forms.Cursor DefaultCursor
		{
			get
			{
				return null;
			}
		}

		public virtual void OnMouseDown(ObjectiveDraw.Platform.DrawerChartBase control, System.Windows.Forms.MouseEventArgs e)
		{
			m_DownMousePosition.X = e.X;
			m_DownMousePosition.Y = e.Y;
			m_MouseIsDown = true;

			if(MouseDown!=null)
			{
				MouseDown(control, e);
			}
		}

		public virtual void OnMouseMove(ObjectiveDraw.Platform.DrawerChartBase control, System.Windows.Forms.MouseEventArgs e)
		{
			(control as DrawerChartBase).MouseOrdinate = DrawerShapeBase.OrdinateFromMouse(control, e.Y);
			(control.FindDevice() as GraphChartDevice).MouseAbscissa = DrawerShapeBase.AbscissaFromMouse(control, e.X);
			(control as DrawerChartBase).ShowMouseOrdinate = true;
			(control.FindDevice() as GraphChartDevice).ShowMouseTime = true;
			control.Invalidate();
			if(MouseMove!=null)
			{
				MouseMove(control, e);
			}
		}

		public virtual void OnMouseUp(ObjectiveDraw.Platform.DrawerChartBase control, System.Windows.Forms.MouseEventArgs e)
		{
			m_MouseIsDown = false;
			if(MouseUp!=null)
			{
				MouseUp(control, e);
			}
		}

		public virtual void OnMouseEnter(ObjectiveDraw.Platform.DrawerChartBase control, System.EventArgs e)
		{
		}

		public virtual void OnMouseLeave(ObjectiveDraw.Platform.DrawerChartBase control, System.EventArgs e)
		{
			(control as DrawerChartBase).ShowMouseOrdinate = false;
			(control.FindDevice() as GraphChartDevice).ShowMouseTime = false;
			control.Invalidate();
		}

		public virtual void OnKeyPress(ObjectiveDraw.Platform.DrawerChartBase control, System.Windows.Forms.KeyPressEventArgs e)
		{
			// TODO:  Add DrawerShapeBase.OnKeyPress implementation
		}
		public virtual void OnKeyDown(ObjectiveDraw.Platform.DrawerChartBase control, System.Windows.Forms.KeyEventArgs e)
		{
			// TODO:  Add DrawerShapeBase.OnKeyDown implementation
		}

	}
}
